<html>
<head><meta charset="utf-8"><title>include! puzzle · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html">include! puzzle</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="242926744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242926744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242926744">(Jun 16 2021 at 19:02)</a>:</h4>
<p>Hey, a couple of folks (60fps &amp; discord) independently reached out to me about <a href="https://github.com/rust-analyzer/rust-analyzer/issues/3767">https://github.com/rust-analyzer/rust-analyzer/issues/3767</a>, and that's a fun issue to think about. </p>
<p>In a nutshell, we can't goto definition inside the <code>include!</code> macro. In some sense, this is expected behavior. From a programming model point of view, <code>include!</code> is indistinguishable from a proc macro which creates the tokens out of thin air (imagine <code>proc_include</code> which does <code>std::fs::read(path).unwrap().parse::&lt;TokenStream&gt;().unwrap()</code>).</p>
<p>From a user's perspective though, the IDE clearly should just "see through" this macro. I wonder if anyone has idea  about how to special case this best?</p>



<a name="242927015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242927015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242927015">(Jun 16 2021 at 19:04)</a>:</h4>
<p>In rustc the spans of the tokens are from the included file, not the macro invocation itself afaik.</p>



<a name="242927167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242927167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242927167">(Jun 16 2021 at 19:05)</a>:</h4>
<p>Maybe something like parse the included file as if it is a regular module and then take the tokens from this module and place them at the macro invocation site? Does that make sense?</p>



<a name="242930733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242930733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242930733">(Jun 16 2021 at 19:31)</a>:</h4>
<p>yeah, rustc has an easier time here since it just loads all files into its source map and can then address any part of any file with a <code>Span</code></p>



<a name="242930988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242930988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242930988">(Jun 16 2021 at 19:33)</a>:</h4>
<p>I think we might be able to special-case this in the builtin macro logic by adding an extra <code>TokenMap</code> there</p>



<a name="242931019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/include%21%20puzzle/near/242931019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/include!.20puzzle.html#242931019">(Jun 16 2021 at 19:33)</a>:</h4>
<p>we already track included files there</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>